package com.yanqu.road.server.cmd.banquet;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.banquet.BanquetConfigMgr;
import com.yanqu.road.server.manger.banquet.BanquetMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

//@Cmd(code = Protocol.S_BANQUET_SERVER_OPEN, desc = "开宴会")
public class OpenBanquetCmd extends AbstractCommand {

	private int type;
	private String invitationId;
	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		BanquetProto.OpenBanquetReq reqMsg = BanquetProto.OpenBanquetReq.parseFrom(packet.getBytes());
		type = reqMsg.getType();
		invitationId = reqMsg.getInvitationId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		if(BanquetConfigMgr.isServerNormalBanquet(type) && !SystemOpenMgr.systemOpen(player, eSystemId.Banquet.getValue())){
			ret = GameErrorCode.E_SYSTEM_NO_OPEN;
			return;
		}
		if(BanquetConfigMgr.isServerFeastBanquet(type) && !SystemOpenMgr.systemOpen(player, eSystemId.BanquetServer.getValue())){
			ret = GameErrorCode.E_SYSTEM_NO_OPEN;
			return;
		}
		ret = BanquetMgr.openBanquet(player,type,invitationId);
		if(0 == ret){
			BanquetMgr.addBanquetConductTimes(player);
		}
	}

	@Override
	public void sendData(GamePlayer player) {
		BanquetProto.OpenBanquetResp.Builder respMsg = BanquetProto.OpenBanquetResp.newBuilder();
		respMsg.setRet(ret);
		player.sendPacket(Protocol.U_BANQUET_SERVER_OPEN, respMsg);
	}
}
